﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="admin_Modules_NewsEvent_Ads_Default" %>


<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="/admin/resources/css/base.css" rel="stylesheet" type="text/css" />
    <script src="/admin/resources/js/base.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        var commandHandler = function (cmd, record) {
            switch (cmd) {
                case "edit":
                    loadAddOrEditContact(record.data.ID.toString());
                    break;
            }
        }


        var renderPublish = function (value, p, record) {
            if (value != null) {
                if (value == true) return "Có"; else return "Không";
            }
            return "Không";
        }

        var reload = function () {
            PagingToolBar1.changePage(1);
        }

        var loadAddOrEditContact = function (id) {
            top.createWindow('addOrEditLink', 'Modules/common/ads/AddOrEdit.aspx?id=' + id + '&cbFX=reload&tId=' + getTabPanelID(), 'Thêm, sửa quảng cáo', 720, 480, true)
        }

        var confirmDeleteContact = function () {
            parent.Ext.Msg.confirm('Xác nhận', '<span style="color:red;text-align:center;">Xóa quảng cáo?</span>', function (btn) {
                if (btn == "yes") {
                    btnDoDelete.fireEvent('click', null);
                }
            });
        }


        var rowSelect = function (sl, index, record) {
            var selectRows = sl.grid.getRowsValues({ selectedOnly: true });
            var count = selectRows.length;
            btnDelete.setDisabled(count == 0);
        }

        var checkNoneAll = function (model) {
            var count = model.getSelections().length;
            btnDelete.setDisabled(count == 0);

        }

        var rowDeSelect = function (sl, index, record) {
            var selectRows = sl.grid.getRowsValues({ selectedOnly: true });
            var count = selectRows.length;
            btnDelete.setDisabled(count == 0);
        }

        var renderImage = function (value) {
            return "<img src='" + value + "?w=80' />";
        }

        var loadCategoryOrderForm = function () {
            var url = "/admin/modules/common/ads/SortCategory.aspx?id=" + id + "&cbFX=reload&tId=" + getTabPanelID();
            window.top.createWindow('sortAds', url, 'Sắp xếp quảng cáo', 580, 460, true);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ScriptManager2" runat="server">
    </ext:ResourceManager>
    <ext:Store ID="storeContact" runat="server" RemoteSort="false" AutoLoad="true">
        <Reader>
            <ext:JsonReader IDProperty="ID" Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="Name" />
                    <ext:RecordField Name="ID" />
                    <ext:RecordField Name="ImageUrl" />
                    <ext:RecordField Name="Url" />
                    <ext:RecordField Name="IsPublish" />
                    <ext:RecordField Name="Order" />
                    <ext:RecordField Name="Position" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <SortInfo Direction="ASC" Field="Order" />
        <AutoLoadParams>
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="20" Mode="Raw" />
        </AutoLoadParams>
        <Proxy>
            <ext:HttpProxy Json="true" Url="Handler.ashx" Method="GET">
            </ext:HttpProxy>
        </Proxy>
    </ext:Store>
    <ext:Viewport ID="ViewPort2" runat="server">
        <Items>
            <ext:BorderLayout ID="BorderLayout1" runat="server">
                <Center>
                    <ext:Panel ID="pnContact" runat="server" Frame="false" AutoScroll="true" Border="false"
                        Layout="Fit" BodyBorder="false">
                        <TopBar>
                            <ext:Toolbar>
                                <Items>
                                    <ext:Button runat="server" ID="btnAdd" Text="Thêm" Icon="Add">
                                        <Listeners>
                                            <Click Handler=" loadAddOrEditContact(0);" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator>
                                    </ext:ToolbarSeparator>
                                    <ext:Button runat="server" ID="btnCategoryOrder" Text="Sắp xếp" Icon="SortAscending">
                                        <Listeners>
                                            <Click Handler=" loadCategoryOrderForm();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator>
                                    </ext:ToolbarSeparator>
                                    <ext:Button Text="Xóa" Icon="Delete" ID="btnDelete" Disabled="true">
                                        <Listeners>
                                            <Click Handler="confirmDeleteContact();"></Click>
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button Hidden="true" ID="btnDoDelete" runat="server">
                                        <DirectEvents>
                                            <Click OnEvent="Delete" Before="parent.Ext.Msg.wait('Đang cập nhật dữ liêu...', 'Saving');    "
                                                Success="parent.Ext.Msg.hide();">
                                            </Click>
                                        </DirectEvents>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <Items>
                            <ext:GridPanel ID="gridViewUser" runat="server" StoreID="storeContact" StripeRows="true"
                                Header="false" Frame="false" Border="false" TrackMouseOver="true" Title="Toàn bộ Văn bản nội bộ"
                                AutoExpandColumn="Url">
                                <ColumnModel ID="ColumnModel1" runat="server">
                                    <Columns>
                                        <ext:RowNumbererColumn Header="STT" Width="30" Align="Center" />
                                        <ext:CommandColumn Align="Center" Width="30" Header="Sửa">
                                            <Commands>
                                                <ext:GridCommand Icon="TableEdit" CommandName="edit" ToolTip-Text="<b style='color:blue;'>Sửa</b>" />
                                            </Commands>
                                        </ext:CommandColumn>
                                        <ext:Column Header="Tên" Sortable="true" DataIndex="Name" Width="180">
                                        </ext:Column>
                                        <ext:Column Header="Liên kết" Sortable="true" DataIndex="Url">
                                        </ext:Column>
                                        <ext:Column Header="Ảnh" Sortable="true" DataIndex="ImageUrl">
                                            <Renderer Fn="renderImage" />
                                        </ext:Column>
                                        <ext:Column Header="Thứ tự" Sortable="true" DataIndex="Order">
                                        </ext:Column>
                                        <ext:Column Header="Thể hiện" Sortable="true" DataIndex="IsPublish">
                                            <Renderer Fn="renderPublish" />
                                        </ext:Column>
                                        <ext:Column Header="Vị trí" Sortable="true" DataIndex="Position">
                                        </ext:Column>
                                    </Columns>
                                </ColumnModel>
                                <LoadMask ShowMask="true" Msg="Đang tải dữ liệu, vui lòng chờ ..." />
                                <SelectionModel>
                                    <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server">
                                        <Listeners>
                                            <RowSelect Fn="rowSelect" />
                                            <RowDeselect Fn="rowDeSelect" />
                                            <SelectionChange Fn="checkNoneAll" />
                                        </Listeners>
                                    </ext:CheckboxSelectionModel>
                                </SelectionModel>
                                <Listeners>
                                    <Command Handler="commandHandler(command,  record);" />
                                </Listeners>
                            </ext:GridPanel>
                        </Items>
                        <BottomBar>
                            <ext:PagingToolbar ID="PagingToolBar1" runat="server" AfterPageText="" BeforePageText="Trang&nbsp;"
                                StoreID="storeContact" DisplayMsg="{0}-{1}/{2}" EmptyMsg="Hiện tại chưa có mẫu tin nào"
                                FirstText="Đầu" LastText="Cuối" NextText="Tiếp" PageSize="20" PrevText="Trước"
                                RefreshText="Làm mới">
                            </ext:PagingToolbar>
                        </BottomBar>
                    </ext:Panel>
                </Center>
            </ext:BorderLayout>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>
